<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        height: 200px;
        width: 200px;
        background-color: red;
      }
    </style>
  </head>
  <div class="box"></div>
  <body>
    <script>
      let oBox = document.querySelector('.box')
      function centent(e) {
        console.log(this, e)
      }
      oBox.onmousemove = intSet(centent, 5000)
      // 封装节流函数
      function intSet(centent, time) {
        let lastTime = 0
        return function (e) {
          let nowTime = Date.now()
          if (nowTime - lastTime < time) {
            return
          }
          lastTime = nowTime
          //实际绑定的函数为return的函数,当前函数中的this指向为节点.当前函数中含有e
          // 所以需要使用call修改this指向
          centent.call(this, e)
        }
      }
    </script>
  </body>
</html>
